//package com.wiloon.javaeex.ios.apns;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import javapns.devices.Device;
//import javapns.devices.implementations.basic.BasicDevice;
//import javapns.notification.AppleNotificationServerBasicImpl;
//import javapns.notification.PushNotificationManager;
//import javapns.notification.PushNotificationPayload;
//import javapns.notification.PushedNotification;
//
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//public class IphonePushService {
//
//	private static Logger logger = LoggerFactory
//			.getLogger(IphonePushService.class);
//
//	/**
//	 *
//	 * @param tokens
//	 *
//	 * @param message
//	 *
//	 * @param badge
//
//	 * @param sound
//
//	 * @param certificatePath
//
//	 * @param certificatePassword
//
//	 * @param single
//
//	 */
//	public void sendpush(List<String> tokens, String message, int badge,
//			String sound, String certificatePath, String certificatePassword,
//			boolean single) {
//
//		try {
//			logger.info("----------------message:" + message);
//			PushNotificationPayload payLoad = new PushNotificationPayload();
//			if (StringUtils.isNotEmpty(message)) {
//				payLoad.addAlert(message);
//			}
//			payLoad.addBadge(badge);
//			if (!StringUtils.isBlank(sound)) {
//				payLoad.addSound(sound);
//			}
//			PushNotificationManager pushManager = new PushNotificationManager();
//
//			pushManager
//					.initializeConnection(new AppleNotificationServerBasicImpl(
//							certificatePath, certificatePassword, false));
//			List<PushedNotification> notifications = new ArrayList<PushedNotification>();
//
//			if (single) {
//				Device device = new BasicDevice();
//				device.setToken(tokens.get(0));
//				PushedNotification notification = pushManager.sendNotification(
//						device, payLoad, true);
//				notifications.add(notification);
//			} else {
//				List<Device> device = new ArrayList<Device>();
//				for (String token : tokens) {
//					device.add(new BasicDevice(token));
//				}
//				notifications = pushManager.sendNotifications(payLoad, device);
//			}
//			List<PushedNotification> failedNotifications = PushedNotification
//					.findFailedNotifications(notifications);
//			// List<PushedNotification> successfulNotifications =
//			// PushedNotification
//			// .findSuccessfulNotifications(notifications);
//			if (failedNotifications != null) {
//				int failed = failedNotifications.size();
//				String errorLog = "failed count=" + failed + "; ";
//				for (PushedNotification failedNotification : failedNotifications) {
//					Device d = failedNotification.getDevice();
//					errorLog += "deviceId=" + d.getDeviceId() + "; token="
//							+ d.getToken();
//				}
//
//				logger.info("message push failed:" + errorLog);
//			}
//			// int successful = successfulNotifications.size();
//		} catch (Exception e) {
//			logger.error("push message exception...", e);
//		}
//	}
//
//	public static void main(String[] args) {
//		String classpath = IphonePushService.class.getResource("/").getPath();
//		// PropertyConfigurator.configure(classpath
//		// + "/config/properties/pushLog4j.properties");
//
//		IphonePushService pushService = new IphonePushService();
//		List<String> token = new ArrayList<String>();
//		String device_token = "aabe5c28aae094f47d80e77efbe9d47c9ccf3a5c28efb18f5524cfdf08e28b85";
//		token.add(device_token);
//		String certificatePath = "D:\\project\\pushDemo\\p12frommac\\\\ipush.p12";
//		String certificatePassword = "abcd@1234";
//
//		pushService.sendpush(token, "hello apns 10", 5, "", certificatePath,
//				certificatePassword, true);
//	}
//}
